package com.xuchang.disruptor;


import com.lmax.disruptor.EventHandler;
import com.xuchang.match.MatchServiceFactory;
import com.xuchang.match.MatchStrategy;
import com.xuchang.model.Order;
import com.xuchang.model.OrderBooks;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

@Data
@Slf4j
public class OrderEventHandler implements EventHandler<OrderEvent> {

    private OrderBooks orderBooks;

    private String symbol;

    public OrderEventHandler(OrderBooks orderBooks) {
        this.orderBooks = orderBooks;
        this.symbol = orderBooks.getSymbol();
    }


    @Override
    public void onEvent(OrderEvent orderEvent, long l, boolean b) throws Exception {
        // 从ringbuffer 里面接收了某个数据
      Order order =  (Order)orderEvent.getSource();
      if (!order.getSymbol().equals(symbol)) { // 我们接收到了一个不属于我们处理的数据,我们不处理
          return;
      }
        //        log.info("开始接收订单事件============>{}", event);
      MatchServiceFactory.getMatchService(MatchStrategy.LIMIT_PRICE).match(orderBooks, order);

        //        log.info("处理完成我们的订单事件===================>{}", event);
    }
}
